// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database();
/*
云函数名称：删除临时订单信息(orderId)
返回格式: {result:success/fail, error:'错误说明',more:''}
*/

exports.main = async (event, context) => {

  let orderId = event.orderId

  // ********************【 删除临时订单信息 】********************

  let tempOrderRemove = await db.collection('temp_orders').where({ orderId: orderId }).remove()
  //------------- 错误检测-err01：临时订单信息删除是否正常
  if (tempOrderRemove.errMsg != 'collection.remove:ok') {
    return { result: 'fail', error: 'err01:网络错误', more: '临时订单[' + orderId + ']删除失败' }
  }

  // ********************【运行至此说明所有操作无误】********************
  return { result: 'success', error: '', more: '' }
}